﻿using CPPEI;
using CPPEI.WebApi;
using SLG.Domain.Services;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SLG.WebApi.Kingdom
{
    /// <summary>
    /// 获取王国
    /// </summary>
    [AuthGetAction("Kingdom", "Get", "1.0")]
    public class GetAction : BaseAction<GetParams, GetResult>
    {
        protected override ActionResult<GetResult> OnExecute(ActionContext context, SysParameters sysParams, GetParams opParams)
        {
            int userId = Convert.ToInt32(context.UserId);

            QueryService service = new QueryService();
            SingleResult<Domain.Datas.KingdomAndKing> serResult = service.QueryKingdom(userId);
            if(serResult.IsSuccess)
            {
                GetResult actResult = new GetResult();
                actResult.KingdomId = serResult.Data.Kingdom.Id;
                actResult.KingdomName = serResult.Data.Kingdom.Name;
                actResult.KingId = serResult.Data.King.Id;
                actResult.KingName = serResult.Data.King.Name;
                actResult.Race = serResult.Data.Kingdom.BDRaceId;
                return new ActionResult<GetResult>(actResult);
            }
            else
            {
                return new ActionResult<GetResult>(serResult);
            }
        }
    }

    public class GetParams
    {
    }

    public class GetResult
    {
        /// <summary>
        /// 王国id
        /// </summary>
        public Guid KingdomId { get; set; }

        public string KingdomName { get; set; }

        /// <summary>
        /// 国王id
        /// </summary>

        public Guid KingId { get; set; }

        public string KingName { get; set; }

        public int Race { get; set; }
    }
}
